#ifndef PAGING_H
#define PAGING_H

#include <asm/types.h>
#include "types.h"
#include "prot.h"

#define phys_to_page(phys) pfn_to_page( (phys) >> PAGE_SHIFT )


// Creating paging structs entries from physical address and paging flags


// 32 bit paging
inline u32 mk_pse32 (u32 addr, u32 flags);
inline u32 mk_pse32_pse36 (u64 addr, u32 flags);

inline void set_pse32 (u32 *table, int pos, u64 addr, u32 flags);

inline void set_flags32   (u32 *entry, u32 flags);
inline void unset_flags32 (u32 *entry, u32 flags);

// pae and 64 bit paging
inline u64 mk_pse64 (u64 addr, u64 flags);

inline void set_pse64 (u64 *table, int pos, u64 addr, u64 flags);

inline void set_flags64     (u64 *entry, u64 flags);
inline void unset_flags64   (u64 *entry, u64 flags);

void map64(u64 *table, unsigned pos, u64 addr_mask, u64 phys);
void flags64(u64 *table, unsigned pos, u64 flags, u64 uflags);



// paging structure - vertex in paging graph
struct test_page {
  u32 offset_mask;
  u64 *virt; // writeable, access page by tester for system purpose
  u64 phys;
  u64 window_offset; // for 1b mappings. for other pages should be 0
};

void pml4_map_kernel(u64 *virt);

#endif /* PAGING_H */